package com.thinkgem.jeesite.modules.sys.service;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.modules.sys.dao. TbShoppingOrderMapper;
import com.thinkgem.jeesite.modules.sys.entity.TbOrder;
import com.thinkgem.jeesite.modules.sys.entity.TbOrderProduct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.Map;
import java.util.List;

/**
 * Created by jyy on 2016/10/19 0019.
 */
@Service
@Transactional(readOnly = false)
public class TbShoppingOrderService {

    @Autowired
    private TbShoppingOrderMapper tbShoppingOrderMapper;

   public TbOrder queryOrder(Integer id) {
        return tbShoppingOrderMapper.selectByPrimaryId(id);
    }
    public List<TbOrderProduct> queryTbOrderProducts(Integer orderId){
        return tbShoppingOrderMapper.queryListOrderProduct(orderId);
    }
    //修改订单状态
    public void editOrderState(Map map){
        tbShoppingOrderMapper.editOrderState(map);
    }


    public Page<TbOrder> findReserveByPage(Page<TbOrder> tbOrderPage, TbOrder tbOrder) {
        tbOrder.setPage(tbOrderPage);
        List list = tbShoppingOrderMapper.findReserveByPage(tbOrder);
        tbOrderPage.setList(list);
        return tbOrderPage;
    }

    public void subStoreNum(TbOrderProduct tbOrderProduct){
        int rows=tbShoppingOrderMapper.subStoreNum(tbOrderProduct);
    }

//user
    // 用户
   public Page<TbOrder> findUserReserveByPage(Page<TbOrder> tbOrderPage, TbOrder tbOrder) {
        tbOrder.setPage(tbOrderPage);
        /*if(tbOrder.getStartTime()!=null&&!tbOrder.getStartTime().equals("")&&tbOrder.getEndTime()!=null&&!tbOrder.getEndTime().equals("")){
           tbOrder.setExtraParam(tbOrder.getStartTime()+"到"+tbOrder.getEndTime());
        }*/
       Date date=tbOrder.getEndDate();
       if(date!=null){
           date.setHours(23);
           date.setMinutes(59);
           date.setSeconds(59);
       }
       List list = tbShoppingOrderMapper.findUserReserveByPage(tbOrder);
        tbOrderPage.setList(list);
        return tbOrderPage;
    }

}
